package com.basker.pisces.domain.entity.meta;

import java.util.List;
import java.util.TreeSet;

import com.basker.pisces.domain.property.meta.Property;

class SubEntityKey {
    final String propertyNames;
    final TreeSet<String> propertyNameSet;

    public SubEntityKey(List<String> propertyNameList) {
        this.propertyNameSet = new TreeSet<>(propertyNameList);
        this.propertyNames = String.join("_", this.propertyNameSet.stream().toArray(s -> new String[s]));
    }

    @Override
    public boolean equals(Object other) {
        if (other instanceof SubEntityKey) {
            return ((SubEntityKey) other).propertyNames.equals(this.propertyNames);
        }

        return false;
    }

    @Override
    public int hashCode() {
        return propertyNames.hashCode();
    }

    @Override
    public String toString() {
        return propertyNames;
    }

    boolean contains(Property<?> property) {
        return propertyNameSet.contains(property.getAlias());
    }

    String[] getPropertyNameArray() {
        return propertyNameSet.toArray(new String[propertyNameSet.size()]);
    }
}
